package org.lt.resume.dao.userdao;

import java.util.List;

import org.lt.resume.dao.userdaoInterface.UserInterface;
import org.lt.resume.domain.users.User;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class UserDAO extends HibernateDaoSupport implements UserInterface {

	public void addUserInfo(User user) {
		this.getHibernateTemplate().save(user);
	}

	public void updateUser(User user) {
		this.getHibernateTemplate().update(user);
	}

	public void getUser(int id) {
		this.getHibernateTemplate().load(User.class, id);
	}

	public User findByUsername(String userName) {
		String sql = "From User u where u.username = '" + userName + "'";
		List users = this.getHibernateTemplate().find(sql);
		if (!users.isEmpty()){
			User user = (User)users.get(0);
			return user;
		}
		
		return null;
	}
	
	public List finUsersByUsername(String userName) {
		return this.getHibernateTemplate().find(
				"From User u where u.username like ?" + userName + "%");
	}

	public void deleteUser(User user){
		this.getHibernateTemplate().delete(user);
	}
}
